package day23;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer2 {

	public static void main(String[] args) {
		ServerSocket ss = null;
		Socket s = null;
		try {
			ss = new ServerSocket(10003);
			s = ss.accept();
			//客户端ip
			String ip = s.getInetAddress().getHostAddress();
			InputStream in = s.getInputStream();
			byte[] buf = new byte[1024];
			int len = in.read(buf);
			System.out.println("客户端ip"+ip);
			System.out.println(new String(buf, 0, len));
			
			OutputStream out = s.getOutputStream();
			out.write("客户端妹妹你好呀！".getBytes());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != s) {
				try {
					s.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
